<?php
/**
 * Created by PhpStorm.
 * User: 宅十三
 * Date: 2021/11/22
 * Time: 11:08
 */
namespace app\demo\controller;


use app\demo\model\Category;
use think\facade\Request;
use think\facade\View;

class Goods {

    public function goodList()
    {
        $param =Request::param();
        $where =[];
        if (isset($param['keywords']) && $param['keywords'] <> '')   $where['keywords'] = $param['keywords'];
        if (isset($param['cid']) && !empty($param['cid'])) $where['cid'] = $param['cid'];

        if (isset($param['is_show']) && $param['is_show'] <> '') $where['is_show'] = $param['is_show'];
        if (isset($param['is_hot']) && $param['is_hot'] <> '') $where['is_hot'] = $param['is_hot'];
        if (isset($param['is_down']) && $param['is_down'] <> '') $where['is_down'] = $param['is_down'];

        if (isset($param['k_time']) && $param['k_time'] <> '') $where['k_time'] = $param['k_time'];
        if (isset($param['j_time']) && $param['j_time'] <> '') $where['j_time'] = $param['j_time'];
        if (isset($param['g_price']) && $param['g_price'] <> '') $where['g_price'] = $param['g_price'];
        if (isset($param['d_price']) && $param['d_price'] <> '') $where['d_price'] = $param['d_price'];


        $list=\app\demo\model\Goods::getGoodList($where);
        View::assign('list',$list);


        //分类
     $cate = Category::getCateAll();
        View::assign('cate',$cate);
        return view('',$where);
    }

    public function goodAdd(){
        return view();
    }

    public function cate(){

        //分类
            $yi=Category::getYr();
            $er=Category::getEr();
            $er = array_unique($er);
            $parentid=input('get.parentid','0');
            $where[]=['parentid','=',"{$parentid}"];
            $list=Category::getCategory($where);
            return View('',['yi'=>$yi,'er'=>$er,'list'=>$list]);
    }
    //分类无限查
    public function getCate($all,$parentid){
        $cate=[];
        foreach ($all as $v){
            if($v["parentid"]==$parentid){
                $cate[$v['id']]=$v;
                $cate[$v['id']]['son']=$this->getCate($all,$v['id']);
            }
        }
        return $cate;
    }

    public function pinList(){

        $where=[];
        $whereOr=[];
        $get=Request::get();
        if(isset($get['brand_logo'])&&count($get['brand_logo'])==1)$where['brand_logo']=$get['brand_logo'][0];
        if(isset($get['if_show'])&&count($get['if_show'])==1) $where['if_show']=$get['if_show'][0];
        if(isset($get['recommended'])) $where['recommended']=$get['recommended'];
        if(isset($get['keywords'])&&$get['keywords']<>'') $where['brand_name']=$get['keywords'];

        $list=\app\demo\model\Brand::getBrandList($where,$whereOr,$get);
        View::assign('list',$list);
        View::assign('get',$get);
        return View('',$get);
    }
    }
